package com.motherchild.admin.controller;

import com.motherchild.admin.dto.InventoryRecordDTO;
import com.motherchild.admin.service.InventoryService;
import com.motherchild.common.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/inventory")
public class InventoryController {

    @Autowired
    private InventoryService inventoryService;

    // 获取库存列表
    @GetMapping("/getList")
    public ApiResponse<List<InventoryRecordDTO>> getInventoryRecords() {
        List<InventoryRecordDTO> records = inventoryService.getInventoryRecords();
        return ApiResponse.success(records);
    }
    // 获取库存列表和记录
    @GetMapping("/getListaaa")
    public ApiResponse<Map<String, List<InventoryRecordDTO>>> getInventoryRecords(@RequestParam(required = false) String name) {
        List<InventoryRecordDTO> inventory = inventoryService.getInventoryRescords(name);
        List<InventoryRecordDTO> records = inventoryService.getRescords(name);
        Map<String, List<InventoryRecordDTO>> map = new HashMap<>();
        map.put("inventory", inventory);
        map.put("records", records);
        return ApiResponse.success(map);
    }


    // 获取库存列表
    @GetMapping("/getStockRecordList")
    public ApiResponse<List<InventoryRecordDTO>> getStockRecordList() {
        List<InventoryRecordDTO> records = inventoryService.getStockRecordList();
        return ApiResponse.success(records);
    }

    // 添加库存记录
    @PostMapping("/addInventoryRecord")
        public ApiResponse<Void> addInventoryRecord(@RequestBody InventoryRecordDTO recordDTO) {
        inventoryService.addInventoryRecord(recordDTO);
        return ApiResponse.success();
    }
    //
}